/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1609984608844_472';

  // add your middleware config here
  config.middleware = [ 'accessLogger', 'exception' ];

  config.httpLog = {
    type: 'all',
  };

  config.validate = {
    convert: true, // 会对入参进行转换
    widelyUndefined: true, // 会把空字符串，NaN,null 这些转成 undefined
  };

  exports.security = {
    xframe: {
      enable: false,
    },
    csrf: {
      enable: false,
    },
  };

  config.cluster = {
    listen: {
      port: 7003,
      hostname: '127.0.0.1',
    }
  };

  config.mysql = {
    app: true,
    agent: false,
    client: {
      host: '127.0.0.1',
      port: '3306',
      user: 'root',
      password: 'root',
      database: 'tashuo',
    },
  };

  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    port: '3306',
    user: 'root',
    password: 'root',
    database: 'tashuo',
    define: {
      timestamps: false, // 不需要sequelize 自动添加事件字段
      freezeTableName: true, // 使用原始表名称
    },
    dialectOptions: {
      dateStrings: true,
      typeCast: true,
    },
    timezone: '+08:00',
  };

  config.qiniu = {
    visitUrl: 'http://paas.star1024.cn',
    bucket: 'mashup2',
    AK: 'TfltdwKungQosxKjV6ZwAOoaen-vJF0DthQljVR7',
    SK: '14UofouMniMf41snDl5dc2wd3MgT1OgLcz8Cj1it'
  };

  // session 配置
  config.session = {
    key: 'egg_house',
    httpOnly: true,
    maxAge: 1000 * 60,
    renew: true,
  };

  // 不需要鉴权的接口
  config.auth = {
    exclude: [ 
      '/cms/admins/login',
    ],
  };

  config.jwt = {
    secret: 'egg_house',
  };

  config.redis = {
    client: {
      port: 6379,
      host: '127.0.0.1',
      password: '',
      db: 0,
    },
    redisExpire: 7 * 24 * 3600,
  };

  // add your user config here
  const userConfig = {
    salt: 'egg_house',
    saltRounds: 10,
    redisExpire: 60 * 60 * 24, // 单位秒
  };

  // 小程序配置
  config.wechatConfig = {
    appId: 'wxfe4ffb4ca400e18c',
    appSecret: 'f132d9a2e91857b0b918cc0051e782f9',
  };

  return {
    ...config,
    ...userConfig,
  };
};
